home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Brailler 0.5ß / Brailler 0.5ß.source / Shell ƒ / buttons.c < prev    next >
Encoding:
Text File  |  1994-10-30  |  5.3 KB  |  142 lines  |  [TEXT/MMCC]

  1.     theFontInfo;
  2.     Rect            tempRect;
  3.     RGBColor        oldForeColor, oldBackColor;
  4.     PixPatHandle    backgroundppat;
  5.     short            theLineHeight;
  6.     Rect            iconRect;
  7.     RGBColor        myWhite={65535, 65535, 65535};
  8.     
  9.     TextFont(geneva);
  10.     TextSize(9);
  11.     TextFace(0);
  12.     GetFontInfo(&theFontInfo);
  13.     theLineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  14.     if (iconHandle!=0L)
  15.     {
  16.         iconRect.left=(buttonRect->right-buttonRect->left)/2+buttonRect->left-16+
  17.             (isDown ? 1 : 0);
  18.         iconRect.right=iconRect.left+32;
  19.         iconRect.top=(buttonRect->bottom-buttonRect->top)/2+buttonRect->top-16+
  20.             (isDown ? 1 : 0)-((theTitle!=0L) ? 5 : 0);
  21.         iconRect.bottom=iconRect.top+32;
  22.     }
  23.     
  24.     if (buttonDepth>2)
  25.     {
  26.         GetForeColor(&oldForeColor);
  27.         GetBackColor(&oldBackColor);
  28.         
  29.         backgroundppat=NewPixPat();
  30.         MakeRGBPat(backgroundppat, (buttonDepth==4) ? &gBackground4Bit :
  31.             &gBackground8Bit);
  32.         SetRect(&tempRect, buttonRect->left+2, buttonRect->top+2,
  33.             buttonRect->right-2, buttonRect->bottom-2);
  34.         
  35.         FillCRect(&tempRect, backgroundppat);
  36.  
  37.         RGBBackColor(&myWhite);
  38.         RGBForeColor(isDown ? ((buttonDepth==4) ? &gBlack4Bit : &gBlack8Bit) :
  39.             ((buttonDepth==4) ? &gWhite4Bit : &gWhite8Bit));
  40.         MoveTo(buttonRect->left, buttonRect->top);
  41.         LineTo(buttonRect->right-2, buttonRect->top);
  42.         MoveTo(buttonRect->left, buttonRect->top+1);
  43.         LineTo(buttonRect->right-3, buttonRect->top+1);
  44.         MoveTo(buttonRect->left, buttonRect->top+2);
  45.         LineTo(buttonRect->left, buttonRect->bottom-2);
  46.         MoveTo(buttonRect->left+1, buttonRect->top+2);
  47.         LineTo(buttonRect->left+1, buttonRect->bottom-3);
  48.         
  49.         RGBForeColor(isDown ? ((buttonDepth==4) ? &gWhite4Bit : &gWhite8Bit) :
  50.             ((buttonDepth==4) ? &gBlack4Bit : &gBlack8Bit));
  51.         MoveTo(buttonRect->right-1, buttonRect->top);
  52.         LineTo(buttonRect->right-1, buttonRect->bottom-1);
  53.         MoveTo(buttonRect->right-2, buttonRect->top+1);
  54.         LineTo(buttonRect->right-2, buttonRect->bottom-1);
  55.         MoveTo(buttonRect->left+2, buttonRect->bottom-2);
  56.         LineTo(buttonRect->right-1, buttonRect->bottom-2);
  57.         MoveTo(buttonRect->left+1, buttonRect->bottom-1);
  58.         LineTo(buttonRect->right-1, buttonRect->bottom-1);
  59.     }
  60.     else
  61.     {
  62.         EraseRect(buttonRect);
  63.         FrameRect(buttonRect);
  64.         if (!isDown)
  65.         {
  66.             MoveTo(buttonRect->left+2, buttonRect->bottom-2);
  67.             LineTo(buttonRect->right-2, buttonRect->bottom-2);
  68.             LineTo(buttonRect->right-2, buttonRect->top+2);
  69.         }
  70.         else
  71.         {
  72.             MoveTo(buttonRect->left+1, buttonRect->bottom-3);
  73.             LineTo(buttonRect->left+1, buttonRect->top+1);
  74.             LineTo(buttonRect->right-3, buttonRect->top+1);
  75.         }
  76.     }
  77.     
  78.     if (theTitle!=0L)
  79.     {
  80.         ForeColor(blackColor);
  81.         MoveTo(buttonRect->left+(buttonRect->right-buttonRect->left)/2-
  82.             (StringWidth(theTitle)/2)+(isDown ? 1 : 0), ((iconHandle!=0L) ?
  83.             buttonRect->bottom-6 : buttonRect->top+
  84.             (buttonRect->bottom-buttonRect->top)/2+theLineHeight/2-2)+
  85.             (isDown ? 1 : 0));
  86.         DrawString(theTitle);
  87.     }
  88.     
  89.     if (iconHandle!=0L)
  90.     {
  91.         if (buttonDepth>2)
  92.             PlotCIcon(&iconRect, (CIconHandle)iconHandle);
  93.         else
  94.         {
  95.             BitMap    iconMap;
  96.             GrafPtr curPort;
  97.             
  98.             GetPort(&curPort);
  99.             HLock( iconHandle);    /* lock data in place */
  100.             
  101.             iconMap.baseAddr = *iconHandle;    /* dereference the handle */
  102.             iconMap.rowBytes = 4;            /* setup other fields */
  103.             SetRect( &iconMap.bounds, 0,0,32,32);
  104.             
  105.             CopyBits( &iconMap, &(curPort->portBits),
  106.                          &iconMap.bounds, &iconRect, srcOr, 0L );
  107.             
  108.             HUnlock(iconHandle);                /* all done; let it float */
  109.         }
  110.     }
  111.     
  112.     if (drawTriangle)
  113.     {
  114.         RgnHandle        triangleRgn;
  115.         
  116.         triangleRgn=NewRgn();
  117.         OpenRgn();
  118.             MoveTo(buttonRect->right-6+(isDown ? 1 : 0), buttonRect->top+5+(isDown ? 1 : 0));
  119.             Line(-TRIANGLE_SIZE, TRIANGLE_SIZE);
  120.             Line(-TRIANGLE_SIZE, -TRIANGLE_SIZE);
  121.             Line(TRIANGLE_SIZE*2, 0);
  122.         CloseRgn(triangleRgn);
  123.         FillRgn(triangleRgn, &qd.black);
  124.         DisposeRgn(triangleRgn);
  125.     }
  126.     
  127.     if (buttonDepth>2)
  128.     {
  129.         DisposPixPat(backgroundppat);
  130.         RGBForeColor(&oldForeColor);
  131.         RGBBackColor(&oldBackColor);    
  132.     }
  133. }
  134.  
  135. Boolean Track3DButton(Rect *buttonRect, unsigned char *theTitle,
  136.     Handle iconHandle, short buttonDepth, Boolean drawTriangle)
  137. {
  138.     Point            mouseLoc;
  139.     Boolean            buttonIsDown;
  140.     
  141.     buttonIsDown=FALSE;
  142.     while (Sti